﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PortManage
{
    public partial class FrmLoading : Form
    {
        public FrmLoading()
        {
            InitializeComponent();
        }

        private void BtnTips_Click(object sender, EventArgs e)
        {
            if(CheckFrmLoading.IsLoad)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("仍在加载中请稍候片刻！","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }

        private void CheckLoadState()
        {
            bool IsLoop = true;

            while (IsLoop)
            {
                if (CheckFrmLoading.IsLoad)
                {
                    this.DialogResult = DialogResult.OK;
                }
                Thread.Sleep(1000);
            }
        }

        private void FrmLoading_Load(object sender, EventArgs e)
        {
            Task taskCheckLoadState = new Task(() => CheckLoadState());
            taskCheckLoadState.Start();
        }
    }

    public static class CheckFrmLoading
    {
        public static bool IsLoad { get; set; }
        public static DataTable FrmMainCacheDT { get; set; }
        public static void setIsLoad(bool value)
        {
            IsLoad = value;
        }
    }
}
